<script lang="ts" setup name="StockRealSheet">
import { CirclePlus, EditPen } from '@element-plus/icons-vue'
import { ProTableInstance } from '~/library/components/ProTable/interface'
import { deleteStockRealSheetAPI, getStockRealSheetAPI } from '~/src/api/procure'
import { stockRealSheetColumn } from './info/columns'
const router = useRouter()
const route = useRoute()
const initParam = ref({ orderType: 1 })
const proTableRef = ref<ProTableInstance>()

const toCreate = (id: string, status?: boolean) => {
  if (id) {
    router.push({
      path: '/procure/stockRealSheetEdit',
      query: {
        id: id,
        type: status ? 'audited' : 'edit',
      },
    })
  } else {
    router.push(`/procure/stockRealSheetEdit?type=add`)
  }
}

// const toDelete = async () => {
//   await useDeleteData(deleteStockRealSheetAPI, proTableRef.value as ProTableInstance)
//   await proTableRef.value?.getTableList()
// }
const toDelete = async (id: number) => {
  await ElMessageBox.confirm('确定该订单吗删除吗?', '温馨提示', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning',
  })
  await deleteStockRealSheetAPI({ id })
  ElMessage.success('删除成功')
  await proTableRef.value?.getTableList()
}
</script>

<template>
  <div class="auto-height-container">
    <pro-table
      ref="proTableRef"
      :columns="stockRealSheetColumn"
      highlight-current-row
      :indent="20"
      :init-param="initParam"
      :isCard="false"
      :pagination="true"
      :request-api="getStockRealSheetAPI"
      row-key="id"
      title="盘点单列表"
    >
      <template #tableHeader>
        <!-- <el-button v-auth="'add'" type="primary" :icon="CirclePlus" @click="toCreate(0)"> 新增 </el-button>  -->
        <el-button v-auth="'add'" :icon="CirclePlus" type="primary" @click="toCreate('')">新增盘点单</el-button>
        <!-- <el-button v-auth="'delete'" @click="toDelete">删除</el-button> -->
      </template>
      <template #orderNo="{ row }">
        <el-button v-auth="'edit'" :icon="EditPen" link type="primary" @click="toCreate(row.orderId, row.checkFlag)">
          {{ row.orderId }}
        </el-button>
      </template>
      <template #operation="scope">
        <!-- <el-button v-if="!scope.row.checkFlag" v-auth="'edit'" link type="primary" @click="toCreate(scope.row.orderId)">编辑</el-button>
        <el-button v-if="scope.row.checkFlag" link type="primary" @click="toCreate(scope.row.orderId)">查看</el-button> -->
        <el-button v-if="!scope.row.checkFlag" v-auth="'delete'" link type="primary" @click="toDelete(scope.row.orderId)">删除</el-button>
      </template>
    </pro-table>
  </div>
</template>

<style lang="scss" scoped></style>
